package cn.rubbit.load;

import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import cn.rubbit.ApplicationContext;
import cn.rubbit.entity.Project;
import cn.rubbit.entity.Project.TYPE;

public class Resource {
	private ResourceBundle rb;

	private Resource() {
		rb = PropertyResourceBundle.getBundle("config");
		ApplicationContext.setParms(ApplicationContext.DB_DRIVER, rb.getString(ApplicationContext.DB_DRIVER));
		ApplicationContext.setParms(ApplicationContext.DB_JARS, rb.getString(ApplicationContext.DB_JARS));
		ApplicationContext.setParms(ApplicationContext.DB_PWD, rb.getString(ApplicationContext.DB_PWD));
		ApplicationContext.setParms(ApplicationContext.DB_URL, rb.getString(ApplicationContext.DB_URL));
		ApplicationContext.setParms(ApplicationContext.DB_USR, rb.getString(ApplicationContext.DB_USR));
	}

	private static Resource instance;

	public static Resource newInstance() {
		if (instance == null) {
			instance = new Resource();
		}
		DriverFactory.getInstance();
		return instance;
	}

	public String get(String key) {
		return rb.getString(key);
	}

	public Project GenerateProject() {
		Project project = new Project();
		project.setArtifactId(rb.getString(ApplicationContext.PJ_ARTIFACT));
		project.setGroupId(rb.getString(ApplicationContext.PJ_GROUP));
		project.setName(rb.getString(ApplicationContext.PJ_NAME));
		if (rb.getString(ApplicationContext.PJ_TYPE).equalsIgnoreCase("jar")) {
			project.setType(TYPE.JAR);
		} else {
			project.setType(TYPE.WAR);
		}
		return project;
	}
}
